/**
 * 题目：
 * 斐波那契数列
 */

// 方案一：递归
export function fibonacci(num:number):number {
    if(num==0) {
      return 0;
    }
    if(num<=2){
      return 1;
    }
    return fibonacci(num - 1) + fibonacci(num - 2)
}

// 方案二： 循环取值
export function fibonacci2(num:number):number {
  if(num==0) return 0;
  if(num<=2) return 1;
  let pre:number = 1,
      next:number = 1,
      result:number = 0;
  for (let index = 3; index <= num; index++) {
    result = pre + next;
    pre = next;
    next = result;
  }
  return result;
}
 